//
//  MyAssetsViewController.m
//  Consume100
//
//  Created by eliot on 16/3/24.
//  Copyright © 2016年 aleven. All rights reserved.
//

#import "MyAssetsViewController.h"

#import "GetIdentifyingViewController.h"
@interface MyAssetsViewController ()

/** 我的金币*/
@property (weak, nonatomic) IBOutlet UILabel *myGoldLb;

/** 余额*/
@property (weak, nonatomic) IBOutlet UILabel *balanceLb;




@end

@implementation MyAssetsViewController

+(MyAssetsViewController*)CreatMyAssetsViewController{
    
    UIStoryboard *story=[UIStoryboard storyboardWithName:@"Main" bundle:nil];
    MyAssetsViewController *myAssets=[story instantiateViewControllerWithIdentifier:@"MyAssetsViewController"];
    return myAssets;
}


- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"我的资产";
    [self.navigationController.navigationBar setTitleTextAttributes:@{NSFontAttributeName:[UIFont systemFontOfSize:19],NSForegroundColorAttributeName:[UIColor whiteColor]}];
    self.navigationController.navigationBar.tintColor = [UIColor whiteColor];
    [self.navigationController.navigationBar setTitleTextAttributes:@{NSForegroundColorAttributeName : [UIColor whiteColor]}];
    self.navigationController.navigationBar.translucent = NO;
    [self addbottomView];
    
    UserModel *model = userModel;
    
    AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
    manager.responseSerializer = [AFHTTPResponseSerializer serializer];
    manager.requestSerializer.timeoutInterval = 5;
    NSDictionary *dic = @{@"consumerId":model.id};
    NSString *baseUrl = [NSString stringWithFormat:@"%@getConsumerInfo.jhtml", MyBaseURL];
    [manager POST:baseUrl parameters:dic progress:^(NSProgress * _Nonnull uploadProgress) {
    } success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
        
        dispatch_async(dispatch_get_main_queue(), ^{
            
            
            NSDictionary *dic = [NSJSONSerialization JSONObjectWithData:responseObject options:NSJSONReadingMutableContainers error:nil];
            self.myGoldLb.text = dic[@"coins"];
            self.balanceLb.text = dic[@"amount"];
            
        });
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        
        dispatch_async(dispatch_get_main_queue(), ^{
          
            [MBProgressHUD hideHUD];
            [MBProgressHUD showError:@"链接超时,请检查网络"];
        });
        
        
    }];
    
}





- (void) addbottomView {
    UIView *backView = [[UIView alloc] init];
    [self.view addSubview:backView];
    float height = (self.view.frame.size.width - 2)/3;
    backView.backgroundColor = [UIColor colorWithRed:205/255.0 green:205/255.0 blue:205/255.0 alpha:0.6];
    [backView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(125);
        make.left.right.mas_equalTo(0);
        make.height.mas_equalTo(height);
    }];
    UIButton *btn1 = [UIButton buttonWithType:UIButtonTypeCustom];
    [backView addSubview:btn1];
    btn1.backgroundColor = [UIColor whiteColor];
    [btn1 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.left.mas_equalTo(0);
        make.size.mas_equalTo(CGSizeMake(height, height));
        NSLog(@"%f", height);
        
    }];
    UIImageView *iv1 = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"icon_TX"]];
    [btn1 addSubview:iv1];
    [iv1 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.center.mas_equalTo(CGPointMake(btn1.center.x, btn1.center.y - 6));
        make.size.mas_equalTo(CGSizeMake(30, 30));
    }];
    UILabel *lb1 = [[UILabel alloc] init];
    lb1.text = @"提现";
    [btn1 addSubview:lb1];
    [lb1 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(iv1.mas_bottom).mas_equalTo(2);
        make.left.right.mas_equalTo(0);
        make.height.mas_equalTo(21);
    }];
    
    
    UIButton *btn2 = [UIButton buttonWithType:UIButtonTypeCustom];
    [backView addSubview:btn2];
    btn2.backgroundColor = [UIColor whiteColor];
    [btn2 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(0);
        make.left.mas_equalTo(btn1.mas_right).mas_equalTo(1);
        make.size.mas_equalTo(CGSizeMake(height, height));
    }];
    UIImageView *iv2 = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"icon_payment_code"]];
    [btn2 addSubview:iv2];
    [iv2 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.center.mas_equalTo(CGPointMake(btn2.center.x, btn1.center.y - 6));
        make.size.mas_equalTo(CGSizeMake(30, 30));
    }];
    UILabel *lb2 = [[UILabel alloc] init];
    lb2.text = @"支付密码";
    [btn2 addSubview:lb2];
    [lb2 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(iv2.mas_bottom).mas_equalTo(2);
        make.left.right.mas_equalTo(0);
        make.height.mas_equalTo(21);
    }];
    
    
    UIButton *btn3 = [UIButton buttonWithType:UIButtonTypeCustom];
    [backView addSubview:btn3];
    btn3.backgroundColor = [UIColor whiteColor];
    [btn3 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.right.mas_equalTo(0);
        make.size.mas_equalTo(CGSizeMake(height, height));
    }];
    UIImageView *iv3 = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"icon_Recharge"]];
    [btn3 addSubview:iv3];
    [iv3 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.center.mas_equalTo(CGPointMake(btn3.center.x, btn1.center.y - 6));
        make.size.mas_equalTo(CGSizeMake(30, 30));
    }];
    UILabel *lb3 = [[UILabel alloc] init];
    lb3.text = @"金币记录";
    [btn3 addSubview:lb3];
    [lb3 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(iv3.mas_bottom).mas_equalTo(2);
        make.left.right.mas_equalTo(0);
        make.height.mas_equalTo(21);
    }];
    
    iv1.contentMode = UIViewContentModeScaleAspectFit;
    iv2.contentMode = UIViewContentModeScaleAspectFit;
    iv3.contentMode = UIViewContentModeScaleAspectFit;
    lb1.textAlignment = NSTextAlignmentCenter;
    lb2.textAlignment = NSTextAlignmentCenter;
    lb3.textAlignment = NSTextAlignmentCenter;
    
    
    
    UIView *centerView = [[UIView alloc] init];
    [self.view addSubview:centerView];
    centerView.backgroundColor = [UIColor colorWithRed:205/255.0 green:205/255.0 blue:205/255.0 alpha:0.6];
    [centerView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(110);
        make.bottom.mas_equalTo(backView.mas_top).mas_equalTo(0);
        make.left.right.mas_equalTo(0);
    }];
    UILabel *bottomLb = [[UILabel alloc] init];
    [backView addSubview:bottomLb];
    bottomLb.backgroundColor = [UIColor colorWithRed:205/255.0 green:205/255.0 blue:205/255.0 alpha:0.6];
    [bottomLb mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.left.right.mas_equalTo(0);
        make.height.mas_equalTo(1);
    }];
    
    [btn1 addTarget:self action:@selector(clickBtn1) forControlEvents:UIControlEventTouchUpInside];
    [btn2 addTarget:self action:@selector(clickBtn2) forControlEvents:UIControlEventTouchUpInside];
    [btn3 addTarget:self action:@selector(clickBtn3) forControlEvents:UIControlEventTouchUpInside];
    
    
}

//点击提现
- (void) clickBtn1 {
    
    UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"您未设置支付密码" message:@"请先设置支付密码" preferredStyle:UIAlertControllerStyleAlert];
    UIAlertAction *action1= [UIAlertAction actionWithTitle:@"去设置" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        GetIdentifyingViewController *vc = [GetIdentifyingViewController CreatGetIdentifyingViewController];
        vc.viewTitle = @"设置支付密码";
        [self creatNav:vc];
    }];
    UIAlertAction *action2 = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        
    }];
    [alert addAction:action1];
    [alert addAction:action2];
    [self presentViewController:alert animated:YES completion:nil];
    
}
//点击支付密码
- (void) clickBtn2 {
    GetIdentifyingViewController *vc = [GetIdentifyingViewController CreatGetIdentifyingViewController];
    vc.viewTitle = @"重置支付密码";
    [self creatNav:vc];
  
}


//点击金币记录
- (void) clickBtn3 {
    
}




//创建模态导航控制器
-(void)creatNav:(UIViewController *)view{
    
    UINavigationController *nav=[[UINavigationController alloc] initWithRootViewController:view];
    nav.navigationBar.barTintColor = [UIColor colorWithRed:254/255.0 green:154/255.0 blue:37/255.0 alpha:1];
    view.navigationItem.leftBarButtonItem=[[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"icon_back"] style:UIBarButtonItemStylePlain target:self action:@selector(dismiss)];
    [self presentViewController:nav animated:YES completion:nil];
}

- (void)dismiss {
    [self dismissViewControllerAnimated:YES completion:nil];
}









- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
